import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileOutputStream;
	import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.concurrent.Semaphore;


	public class XlsThread extends Thread {
		ExcelReader exc;
		public DoublyLinkedList[] hArray;
		public DoublyLinkedList[] mArray;
		public DoublyLinkedList[] nArray;
		public DoublyLinkedList[] xArray=new DoublyLinkedList[1];
		  
		String x="_elec15.xls";
	    ZipThread dt; 
	    Semaphore a,b,c; 
	    String lineContent = null;
	    Ranking ran=new Ranking();
		public XlsThread(ExcelReader exc2,Semaphore a1,Semaphore a2,Semaphore a3){
			 exc=exc2;
			 a=a1;b=a2;c=a3;
			
		}
		
		public void run(){
			/*try{ 
		     	 
				 b.acquire();
				 a.acquire();
				 
				}catch(InterruptedException e){}*/
			try{
				   
				Thread.sleep(900);
				}
				catch(InterruptedException e){
					 
				}
			  
		      
		       ran.DailyRank(readTex("link.txt"));
			   c.release();
			
		}
		public DoublyLinkedList[] readTex(String v) {
			
			String lineContent = null;
			xArray[0]=new DoublyLinkedList();
			
		    try {
		      
		      InputStream is = getClass().getResourceAsStream(v);
		      BufferedReader br = new BufferedReader
		      
		         (new InputStreamReader(is));
		      while ((lineContent = br.readLine()) != null) {
					
	          hArray= exc.readlast("D://"+lineContent+x,lineContent);
	          Double qa=hArray[0].getValue();
		      String la=hArray[0].getPlace();
		      xArray[0].insert(la,qa);
	          System.out.println(xArray[0].getCount());    
		         }
		      mArray=exc.readlast("D://hsci_p1NO_MBRSelec15.xls","hsci_p1NO_MBRS");
		      Double sa=mArray[0].getValue();
		      String ta=mArray[0].getPlace();
		      xArray[0].insert(ta, sa);
		      nArray=exc.readlast("D://hsci_p2elec15.xls","hsci_p2");
		      Double fa=nArray[0].getValue();
		      String ga=nArray[0].getPlace();
		      xArray[0].insert(ga, fa);
		   
		   
		      }
		    catch (Exception e) {
		      e.printStackTrace();
		      }
			return xArray;
		   
			   
		  }
		
			
		}


